package com.xiashitech.agent.dns;

import io.grpc.NameResolver;
import io.grpc.NameResolverProvider;

import java.net.URI;

public class GrpcResolverProvider extends NameResolverProvider{
    private int targetPort;
    @Override
    public NameResolver newNameResolver(URI targetUri, NameResolver.Args args) {
        //args.getChannelLogger().
        System.out.println("newNameResolver called, targetUri: " + targetUri + ", " + targetUri.getHost() + ", " + targetUri.getPort() + ", args: " + args);
        targetPort = targetUri.getPort();
        //return super.newNameResolver(targetUri, args);
        return new GrpcNameResolver(targetUri.getHost(), targetPort);// targetUri.getPort());
    }

    @Override
    protected boolean isAvailable() {
        return true;
    }

    @Override
    protected int priority() {
        return 10;
    }

    @Override
    public String getDefaultScheme() {
        return "xiashi";
    }
}
